package org.csu.pet_store_2.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.pet_store_2.Domain.Item;
import org.csu.pet_store_2.Domain.Product;
import org.csu.pet_store_2.Service.ProductService;
import org.csu.pet_store_2.persistence.ItemMapper;
import org.csu.pet_store_2.persistence.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class ProductServiceIml implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ItemMapper itemMapper;

    public ArrayList<Item> getItemByProductId(String ProductId)
    {
        ArrayList<Item> items=new ArrayList<>();
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("productid",ProductId);
        List<Item> itemList= itemMapper.selectList(queryWrapper);
        items.addAll(itemList);
        return items;
    }

    public Product getProductByProductId(String ProductId)
    {
        Product product =productMapper.selectById(ProductId);
        return product;
    }
}
